package com.ayuan.blog.service.impl;

import com.github.pagehelper.PageInfo;
import org.durcframework.core.expression.ExpressionQuery;
import org.durcframework.core.service.CrudService;
import com.ayuan.blog.service.ImageService;
import com.ayuan.blog.dao.ImageDao;
import com.ayuan.blog.domain.Image;
import com.ayuan.blog.domain.sch.ImageSch;
import org.springframework.stereotype.Service;

import java.util.List;
    
@Service
public class ImageServiceImpl 
        extends CrudService<Image, ImageDao> 
        implements ImageService {

    @Override
    public PageInfo<Image> findPage(ImageSch sch) {
        ExpressionQuery query = new ExpressionQuery();
        query.addPaginationInfo(sch);
        query.addAnnotionExpression(sch);

        long total = this.getDao().findTotalCount(query);
        List<Image> list = this.getDao().find(query);

        PageInfo<Image> page = new PageInfo<Image>();
        page.setList(list);
        page.setPageNum(sch.getPageIndex()); // 设置当前页数
        page.setPageSize(sch.getPageSize()); // 设置每页的数量
        page.setSize(list.size()); // 设置当前页的数量
        page.setPages((int) ((total + sch.getPageSize() - 1) / sch.getPageSize())); // 设置总的页数
        page.setTotal(total); // 设置总的数量

        return page;
    }
}